[t:/]$ 지식_

s3에서 파일 가져오기

2019/08/22

아마존 문서에서 크리덴셜만 추가.

자바와 닷넷은 모르고 PHP쓰면 븅딱이라고 놀림 받으니까 파이썬으로 해야 하는데 파이썬은 또 공식지원은 아직 아닌가봄. 여튼 아마존이 오픈한 boto를 설치

pip install boto

다음 코드는 예제에서 온 것

https://github.com/awsdocs/aws-doc-sdk-examples/blob/master/python/example_code/s3/put_object.py

import logging
import boto3
from botocore.exceptions import ClientError

def get_object(bucket_name, object_name):

    # Retrieve the object
    s3 = boto3.client('s3',
         aws_access_key_id='AK사대강',
         aws_secret_access_key= 'OcC이산화까스')    
    try:
        response = s3.get_object(Bucket=bucket_name, Key=object_name)
    except ClientError as e:
        # AllAccessDisabled error == bucket or object not found
        logging.error(e)
        return None
    # Return an open StreamingBody object
    return response['Body']

def main():
    """Exercise get_object()"""

    # Assign these values before running the program
    test_bucket_name = 'dmp-dob-test'
    test_object_name = 'test_190709.tsv'

    # Set up logging
    logging.basicConfig(level=logging.DEBUG,
                        format='%(levelname)s: %(asctime)s: %(message)s')

    # Retrieve the object
    stream = get_object(test_bucket_name, test_object_name)
    if stream is not None:
        # Read first chunk of the object's contents into memory as bytes
        data = stream.read(amt=1024)

        print data

if __name__ == '__main__':
    main()




공유하기













[t:/] is not "technology - root". dawnsea, rss